package com.liwenfeng.diancanspringboot.controller.admin;

import com.liwenfeng.diancanspringboot.common.result.PageResult;
import com.liwenfeng.diancanspringboot.common.result.Result;
import com.liwenfeng.diancanspringboot.pojo.dto.SetmealDTO;
import com.liwenfeng.diancanspringboot.pojo.dto.SetmealPageQueryDTO;
import com.liwenfeng.diancanspringboot.pojo.vo.DishVO;
import com.liwenfeng.diancanspringboot.pojo.vo.SetmealVO;
import com.liwenfeng.diancanspringboot.service.SetmealDishService;
import com.liwenfeng.diancanspringboot.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminSetmealController")
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐管理")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private SetmealDishService setmealDishService;
    @PutMapping
    @ApiOperation("修改套餐")
    public Result<String> update(@RequestBody SetmealDTO setmealDTO){
        setmealService.update(setmealDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping("status/{status}")
    @ApiOperation("启用或禁用套餐")
    public Result<String> changeStatus(@PathVariable Integer status, Long id){
        setmealService.changeStatus(status, id);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result<String> delete(@RequestParam List<Long> ids){
        setmealService.delete(ids);
        return Result.success();
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result<String> save(@RequestBody SetmealDTO setmealDTO){
        setmealService.save(setmealDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Long id){
        SetmealVO setmealVO = setmealService.getById(id);
        return Result.success(setmealVO);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    public Result<List<SetmealVO>> list(long categoryId){
        log.info("查询菜品列表: {}", categoryId);
        List<SetmealVO> dishVOs = setmealService.listByCategoryId(categoryId);
        return Result.success(dishVOs);
    }

}
